package com.flower.oauth2.controller;

import com.flower.oauth2.entity.SysUser;
import com.flower.oauth2.service.SysUserService;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.KeyPair;
import java.security.interfaces.RSAPublicKey;
import java.util.Map;

/**
 * @ClassName Public
 * @Description 公钥提供控制器
 * @Date 2021/08/24
 * @Author wuhanxiong
 */
@Controller
@RequestMapping("public")
public class PublicKeyController {

    @Autowired
    private KeyPair keyPair;

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("key")
    @ResponseBody
    public Map<String,Object> getPublicKey(){
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        RSAKey key = new RSAKey.Builder(publicKey).build();
        return new JWKSet(key).toJSONObject();
    }


}
